<?php

namespace app\admin\model;

use think\Model;


class StudentLessonCodes extends Model
{

    

    

    // 表名
    protected $name = 'studebt_lesson_codes';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'code_type_text'
    ];
    

    
    public function getCodeTypeList()
    {
        return ['weekly' => __('Weekly'), 'daily' => __('Daily')];
    }


    public function getCodeTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['code_type']) ? $data['code_type'] : '');
        $list = $this->getCodeTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function category()
    {
        return $this->belongsTo('app\admin\model\student\course\Category', 'category_id', 'category_id', [], 'LEFT')->setEagerlyType(0);
    }


    public function semesters()
    {
        return $this->belongsTo('app\admin\model\student\Semesters', 'semester_id', 'semester_id', [], 'LEFT')->setEagerlyType(0);
    }
}
